import { reactive, ref } from 'vue';
import { defineStore } from "pinia";

const app = defineStore('app', () => {
  /** 设备信息 */
  const appInfo = reactive({
    platform: '', // 设备平台
    bottomSafeArea: '', // 底部安全栏
  })

  /** 是否需要更新用户信息 */
  const isReloadUserInfo = ref(false);

  /** 更新标识 */ 
  const uploadReloadUserInfo = (isReload: boolean) => {
    isReloadUserInfo.value = isReload;
  }

  // 获取设备信息
  const getDeviceInfo = () => {
    uni.getSystemInfo({
      success: (res: any) => {
        console.log('设备信息', res);
        setAppPlatform(res);
        setBottomSafeArea(res);
      }
    })
  }
  // 设置设备平台
  const setAppPlatform = (res: any) => {
    appInfo.platform = res.osName;
  }
  // 设置设备平台
  const setBottomSafeArea = (res: any) => {
    appInfo.bottomSafeArea = String(res.safeAreaInsets.bottom);
  }

  return {
    appInfo,
    getDeviceInfo,
    isReloadUserInfo,
    uploadReloadUserInfo
  }
})
export default app;